package com.hgy.commonsale.webui.action.product;

import java.io.File;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.geln.web.status.Status;


import com.hgy.commonsale.product.GoodKinds;
import com.hgy.commonsale.product.Goods;
import com.hgy.commonsale.service.GoodKindManagerService;
import com.hgy.commonsale.service.GoodManagerService;
import com.hgy.commonsale.webui.action.AnonymousAction;
import com.opensymphony.webwork.ServletActionContext;


/**
 * ��Ʒ��¼��Ȳ���
 * @author guox
 *
 */
public class GoodRecorderAction extends AnonymousAction {
	
	private String goodName;
	private String color;
	private String size;
	private String goodDescriptionEn;
	private String url;
	
	private String price;
	private String isNew;
	private String isSpecial;
	private String selectKind;
	private String selectKindName;
	private GoodKindManagerService goodKindManagerService;
	
	private final String TRUE="true";
	private final String FALSE="false";
	
	private List<GoodKinds> lstKindList;
	
	private File fileUpload;
	
	private GoodManagerService goodManagerService;
	
	//ActionContext 
	
	
	public String execute(){
		
		return INPUT;
	}
	
	public String doSaveGoodDispathcher(){
		lstKindList=goodKindManagerService.getKindsList();
		
		return INPUT;
		
	}
	
	public String doSaveOneGood(){
		
		String path=ServletActionContext.getServletContext().getRealPath("/");
		Goods good=new Goods();
		good.setGoodKindName(goodName);
		good.setColor(color);
		good.setSize(size);
		good.setGoodDescriptionEn(goodDescriptionEn);
		
		//�۸�
		good.setPrice(new BigDecimal(price));
		if(TRUE.equals(isNew)){
			good.setIsNew(true);
		}else if(FALSE.equals(isNew)){
			good.setIsNew(false);
		}
		
		if(TRUE.equals(isSpecial)){
			good.setIsSpecial(true);
		}else if(FALSE.equals(isSpecial)){
			good.setIsSpecial(true);
		}
		
		String trace=path+"tradesPicture\\";
		String newFileName=new Date().getTime()+".jpg";
	
		//�ļ��������
		fileUpload.renameTo(new File(trace+newFileName));
		good.setUrl(newFileName);
		good.setIsActive(true);
		good.setGoodKindID(selectKind);
	//	good.setGoodKindName(selectKindName);
		
		Status status=(Status)goodManagerService.saveObject(good);
		if(Status.SUCCESS.equals(status)){
			return SUCCESS;
		}else if(Status.FAILED.equals(status)){
			return INPUT;
		}
		
		return INPUT;
		
	}
	
	
	protected void uploadImage(){
		
	}
	
	public String getGoodName() {
		return goodName;
	}

	public void setGoodName(String goodName) {
		this.goodName = goodName;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getGoodDescriptionEn() {
		return goodDescriptionEn;
	}

	public void setGoodDescriptionEn(String goodDescriptionEn) {
		this.goodDescriptionEn = goodDescriptionEn;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public String getIsNew() {
		return isNew;
	}

	public void setIsNew(String isNew) {
		this.isNew = isNew;
	}

	public String getIsSpecial() {
		return isSpecial;
	}

	public void setIsSpecial(String isSpecial) {
		this.isSpecial = isSpecial;
	}

	public GoodKindManagerService getGoodKindManagerService() {
		return goodKindManagerService;
	}

	public void setGoodKindManagerService(
			GoodKindManagerService goodKindManagerService) {
		this.goodKindManagerService = goodKindManagerService;
	}

	public List<GoodKinds> getLstKindList() {
		return lstKindList;
	}

	public void setLstKindList(List<GoodKinds> lstKindList) {
		this.lstKindList = lstKindList;
	}

	public String getSelectKind() {
		return selectKind;
	}

	public void setSelectKind(String selectKind) {
		this.selectKind = selectKind;
	}

	public String getSelectKindName() {
		return selectKindName;
	}

	public void setSelectKindName(String selectKindName) {
		this.selectKindName = selectKindName;
	}

	public File getFileUpload() {
		return fileUpload;
	}

	public void setFileUpload(File fileUpload) {
		this.fileUpload = fileUpload;
	}

	public GoodManagerService getGoodManagerService() {
		return goodManagerService;
	}

	public void setGoodManagerService(GoodManagerService goodManagerService) {
		this.goodManagerService = goodManagerService;
	}


}
